var express = require("express");
var router = express.Router();
 let {studentModel} = require("../models/studentModel") //导入学生模型
 /*获取所有学生 */
router.get("/GetAllStudents", async (req, res, next) => {
  let result = await studentModel.find(req.query); //有值为精确查询，没值为全部查询
  if (result) {
    res.send({
      code: 200,
      obj: result,
    });
  }
});
 router.post("/updateStudent", async (req, res) => {
    let { matchedCount } = await studentModel.updateOne(
      { phone: req.body.phone },
      {
        avatar: req.body.avatar,
        gender: req.body.gender,
        name: req.body.name,
        password: req.body.password,
        phone: req.body.phone,
      }
    );
    if (matchedCount == 1) {
      res.send({
        code: 200,
        message: "修改成功",
        data:{avatar: req.body.avatar,
            gender: req.body.gender,
            name: req.body.name,
            password: req.body.password,
            phone: req.body.phone,}
      });
    } else {
      res.send({
        code: 200,
        message: "修改不成功",
      });
    }
  });
  module.exports = router;